package com.c.ctgproject.ui.vehiclefiles

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.c.ctgproject.base.BaseViewModel
import com.c.ctgproject.entity.ResultEntity
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.mode.Recheck
import com.c.ctgproject.retrofit.HttpHelper
import com.c.ctgproject.retrofit.Response
import com.c.ctgproject.retrofit.Service
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.awaitSync
import com.c.ctgproject.utils.commonAwaitSync
import com.c.ctgproject.utils.launch
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import okhttp3.MultipartBody

class VehiclefilesViewModel : BaseViewModel() {
    private val responsedata: MutableLiveData<Response<Recheck>> = MutableLiveData()
    private val EntranceCardata: MutableLiveData<Response<*>> = MutableLiveData()
    private val serviece = HttpHelper.getInstance().create(Service::class.java)



     val canOut = MutableLiveData(0)

    fun getresponsedata(): MutableLiveData<Response<Recheck>> {
        return responsedata
    }

    fun getEntranceCardata(): MutableLiveData<Response<*>> {
        return EntranceCardata
    }



    //车辆二验信息
    fun recheck(token: String, carCode: String) {
        serviece.recheck(token, carCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<Response<Recheck>> {
                override fun onError(e: Throwable) {
                    Log.d("错误信息", "" + e.message)
                    e.printStackTrace()
                }

                override fun onComplete() {}
                override fun onSubscribe(d: Disposable) {}
                override fun onNext(data: Response<Recheck>) {
                    responsedata.value = data
                }
            })
    }

    //车辆二验 上传数据
    fun addEntranceCar(token: String, map: Map<String, String>) {
        serviece.addEntranceCar(token, map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<Response<*>> {
                override fun onError(e: Throwable) {
                    MyLog.d("二验错误${e.message}")
                    e.printStackTrace()
                }

                override fun onComplete() {
                }

                override fun onSubscribe(d: Disposable) {
                }

                override fun onNext(data: Response<*>) {
                    MyLog.d("2验数据上传回调${data}")
                    EntranceCardata.value = data
                }
            })
    }
}